/**
 * Created with IntelliJ IDEA.
 * User: ajhin
 * Date: 5/5/13
 * Time: 11:07 PM
 * To change this template use File | Settings | File Templates.
 */
package societyGames.codeAlong.model
{
import societyGames.xmlFragment.XMLContainer;
import societyGames.xmlFragment.XMLFragmentEditList;

public class SolutionsContainer extends XMLContainer
{
  [Bindable]
  [FragmentCollection(className="societyGames.codeAlong.model.Solution", nodeName="solution")]
  public var solutions:XMLFragmentEditList;

  public function getSolution(id:String):Solution
  {
    //New module, create a new solution.
    if (id == "-1")
    {
      solution = Solution(solutions.addEditItem());
      solution.id = id;
      return solution;
    }

    //Find an existing solution.
    for each(var solution:Solution in solutions.editItems)
    {
      if (solution.id == id)
      {
        return solution;
      }
    }

    //Create a new solution as it didn't exist previously.
    solution = Solution(solutions.addEditItem());
    solution.id = id;
    return solution;
  }
}
}
